package com.zx.bean;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;


public class SendTaskDAOImpl implements ISendTaskDAO {
	private Connection conn = null;
	private PreparedStatement pstmt = null;
	private Statement stmt = null;
	public SendTaskDAOImpl(Connection conn) {
		this.conn = conn;
	}

	public List<Object[]> findSendTask() throws Exception {
		ResultSet rs = null;
		boolean bFlag = false;
		List list = new ArrayList();
		String sql = "select * from sendtask where issend='0'";
		try {
			this.pstmt = conn.prepareStatement(sql);
			rs = this.pstmt.executeQuery();
			if (rs.next()) {
				// 实例化UserBean的一个对象
				SendTask st = new SendTask();
				st.setSenddate(rs.getDate("senddate"));
				st.setMobileno(rs.getString("mobileno"));
				st.setContent(rs.getString("content"));
				st.setIssend(rs.getString("issend"));
				st.setFromuser(rs.getString("fromuser"));
				// 将user添加到list中
				list.add(st);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (rs != null) {
				rs.close();
			}
			if (pstmt != null) {
				pstmt.close();
			}
		}
		// 返回list对象
		return list;
	}

	public boolean updateSendTask(String mobile) throws Exception {
		ResultSet rs = null;
		boolean bFlag = false;
		String sql = "update sendtask set issend='1' where mobileno=" + mobile;

		try {
			int rst = stmt.executeUpdate(sql);
			if (rst != 0) {
				bFlag = true;
			}			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (rs != null) {
				rs.close();
			}
			if (pstmt != null) {
				pstmt.close();
			}
			if (stmt != null) {
				stmt.close();
			}
		}
		return bFlag;
	}

}
